package com.global.gbinventory.barang.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.LineBorder;
import javax.swing.event.TableModelListener;

import com.global.gbinventory.main.model.GBTableModel;

public class GudangFrame extends JInternalFrame {

	private static final long serialVersionUID = -2068490899102320704L;

	private JTable table;
	
	private JButton btnNew;
	private JButton btnDelete;
	private JButton btnSave;
	private JButton btnClose;

	/**
	 * Create the frame.
	 */
	public GudangFrame() {
		//resizeable, closeable, maximizable, iconifiable
		super("Gudang Barang", false, true, false, true);
		setBounds(100, 100, 474, 499);
		getContentPane().setLayout(null);
		
		JPanel panelButtons = new JPanel();
		FlowLayout fl_panelButtons = (FlowLayout) panelButtons.getLayout();
		fl_panelButtons.setVgap(12);
		panelButtons.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelButtons.setBounds(10, 11, 438, 49);
		getContentPane().add(panelButtons);
		
		btnNew = new JButton("New");
		panelButtons.add(btnNew);
		
		btnDelete = new JButton("Delete");
		panelButtons.add(btnDelete);
		
		btnSave = new JButton("Save");
		panelButtons.add(btnSave);
		
		btnClose = new JButton("Close");
		panelButtons.add(btnClose);
		
		JPanel panelTable = new JPanel();
		panelTable.setBounds(10, 71, 438, 388);
		getContentPane().add(panelTable);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(435, 380));
		panelTable.add(scrollPane);
		
		table = new JTable();
		scrollPane.setViewportView(table);


	}
	
	public void displayFrame(){
		setVisible(true);
	}

	public int getTableSelectedRow(){
		return table.getSelectedRow();
	}
	
	public void enableButtonSave(){
		btnSave.setEnabled(true);
	}
	
	public void disableButtonSave(){
		btnSave.setEnabled(false);
	}
	
	public boolean isButtonSaveEnabled(){
		return btnSave.isEnabled();
	}
	
	public void setTableModel(GBTableModel tableModel){
		table.setModel(tableModel);
	}
	
	public void addBtnNewListener(ActionListener l){
		btnNew.addActionListener(l);
	}
	
	public void addBtnDeleteListener(ActionListener l){
		btnDelete.addActionListener(l);
	}
	
	public void addBtnSaveListener(ActionListener l){
		btnSave.addActionListener(l);
	}

	public void addBtnCloseListener(ActionListener l){
		btnClose.addActionListener(l);
	}
	
	public void addTableListener(TableModelListener l){
		table.getModel().addTableModelListener(l);
	}
	
}
